﻿namespace CRMG.Container.Source.OpManager
{
    using CRMG.Container.Resources.ExceptionResources;
    using CRMG.Container.Source.BO;
    using CRMG.Container.Source.DL;
    using CRMG.Container.Source.Variables;
    using Guru.ErrorHandling;
    using System;
    using System.Data;

    public class LookupManager
    {

        #region [ CourseTypes ]

        public DataTable GetCourseTypes()
        {
            try
            {
                CourseTypesDL ctDL = new CourseTypesDL();
                return ctDL.GetCourseTypes();
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2094,
                    Title = Rc.GetString(2094)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ Departments ]

        public DataTable GetDepartments()
        {
            try
            {
                Institute dp = new Institute() { IsActive = 1 };
                InstituteDL dept = new InstituteDL();
                return dept.GetWhereChangeColumnList(dp);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2001,
                    Title = Rc.GetString(2001)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ Positions ]

        public DataTable GetPositions()
        {
            try
            {
                Position pst = new Position() { IsActive = 1 };
                PositionDL post = new PositionDL();
                return post.GetWhereChangeColumnList(pst);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2002,
                    Title = Rc.GetString(2002)
                };
                throw new GuruException(exc, logger);
            }
        }

        public int AddPosition(Position pPosition)
        {
            try
            {
                PositionDL pstnDL = new PositionDL();
                return pstnDL.InsertAndGetId(pPosition);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2046,
                    Title = Rc.GetString(2046)
                };
                throw new GuruException(exc, logger);
            }
        }

        public void UpdatePosition(Position pPosition)
        {
            try
            {
                PositionDL pstnDL = new PositionDL();
                pstnDL.Update(pPosition);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2047,
                    Title = Rc.GetString(2047)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ Schools ]

        public DataTable GetSchools()
        {
            try
            {
                School schl = new School() { IsActive = 1 };
                SchoolDL schlDL = new SchoolDL();
                return schlDL.GetWhereChangeColumnList(schl);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2003,
                    Title = Rc.GetString(2003)
                };
                throw new GuruException(exc, logger);
            }
        }

        public int AddSchool(School pSchool)
        {
            try
            {
                SchoolDL pstnDL = new SchoolDL();
                return pstnDL.InsertAndGetId(pSchool);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2050,
                    Title = Rc.GetString(2050)
                };
                throw new GuruException(exc, logger);
            }
        }

        public void UpdateSchool(School pSchool)
        {
            try
            {
                SchoolDL pstnDL = new SchoolDL();
                pstnDL.Update(pSchool);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2051,
                    Title = Rc.GetString(2051)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ Companies ]

        public DataTable GetCompanies()
        {
            try
            {
                Company cmny = new Company() { IsActive = 1 };
                CompanyDL cmpnyDL = new CompanyDL();
                return cmpnyDL.GetWhereChangeColumnList(cmny);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2004,
                    Title = Rc.GetString(2004)
                };
                throw new GuruException(exc, logger);
            }
        }

        public int AddCompany(Company pCompany)
        {
            try
            {
                CompanyDL cmpnyDL = new CompanyDL();
                return cmpnyDL.InsertAndGetId(pCompany);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2038,
                    Title = Rc.GetString(2038)
                };
                throw new GuruException(exc, logger);
            }
        }

        public void UpdateCompany(Company pCompany)
        {
            try
            {
                CompanyDL cmpnyDL = new CompanyDL();
                cmpnyDL.Update(pCompany);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2039,
                    Title = Rc.GetString(2039)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ Grades ]

        public DataTable GetGrades()
        {
            try
            {
                Grade grd = new Grade() { IsActive = 1 };
                GradeDL grdDL = new GradeDL();
                return grdDL.GetWhereChangeColumnList(grd);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2008,
                    Title = Rc.GetString(2008)
                };
                throw new GuruException(exc, logger);
            }
        }

        public int AddGrade(Grade pGrade)
        {
            try
            {
                GradeDL grdDL = new GradeDL();
                return grdDL.InsertAndGetId(pGrade);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2042,
                    Title = Rc.GetString(2042)
                };
                throw new GuruException(exc, logger);
            }
        }


        public void UpdateGrade(Grade pGrade)
        {
            try
            {
                GradeDL grdDL = new GradeDL();
                grdDL.Update(pGrade);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2043,
                    Title = Rc.GetString(2043)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ Institute ]

        public DataTable GetInstitutes()
        {
            try
            {
                Institute inst = new Institute() { IsActive = 1 };
                InstituteDL instDL = new InstituteDL();
                return instDL.GetWhereChangeColumnList(inst);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2002,
                    Title = Rc.GetString(2002)
                };
                throw new GuruException(exc, logger);
            }
        }

        public int AddInstitute(Institute pInstitute)
        {
            try
            {
                InstituteDL pstnDL = new InstituteDL();
                return pstnDL.InsertAndGetId(pInstitute);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2046,
                    Title = Rc.GetString(2046)
                };
                throw new GuruException(exc, logger);
            }
        }

        public void UpdateInstitute(Institute pInstitute)
        {
            try
            {
                InstituteDL pstnDL = new InstituteDL();
                pstnDL.Update(pInstitute);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2046,
                    Title = Rc.GetString(2046)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion


        #region [ Vendors ]

        public DataTable GetVendors()
        {
            try
            {
                VendorDL vndDL = new VendorDL();
                return vndDL.GetVendors();
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2087,
                    Title = Rc.GetString(2087)
                };
                throw new GuruException(exc, logger);
            }
        }

        public int AddVendor(Vendor pVendor)
        {
            try
            {
                VendorDL vndDL = new VendorDL();
                return vndDL.InsertAndGetId(pVendor);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2088,
                    Title = Rc.GetString(2088)
                };
                throw new GuruException(exc, logger);
            }
        }

        public void UpdateVendor(Vendor pVendor)
        {
            try
            {
                VendorDL vndDL = new VendorDL();
                vndDL.Update(pVendor);
            }
            catch (Exception exc)
            {
                LogEntry logger = new LogEntry(AppVariables.CurrentUser.OBJID)
                {
                    ErrorCode = 2089,
                    Title = Rc.GetString(2089)
                };
                throw new GuruException(exc, logger);
            }
        }

        #endregion

    }
}
